<template>
  <div id="">
    <h2 v-title="'我的银行卡'"></h2>
    <none-list :noneCollect="'您还没有添加银行卡'" v-if="noneList"></none-list>
    <ul class="bankcardList" v-else>
      <li v-for="(bankcard,index) in cardList" :key="bankcard.key" >
        <a class="cardA" @click="pickBankcard(index)">
        <div class="">
          <p>{{bankcard.bankName}}</p>
          <p>{{bankcard.cardTruename}}</p>
        </div>
        <div class="">
          <span class="bankNum">
            {{bankcard.cardNo}}
            <i></i>
          </span>
        </div>
      </a>
        <div class="" style="margin-top:-20px;">
          <p align="right">
            <router-link :to="{ path: 'editBankCard', query: { bankcard: bankcard}}">
              <img src="@/assets/images/edit@2x.png" alt="" class="editImg">
            </router-link>
            <img src="@/assets/images/delete@2x.png" alt="" class="deleteImg" @click="delBank(bankcard.cardId)">
          </p>
        </div>
      </li>
    </ul>
    <div class="p10">
      <button type="button" name="button" class="blockBtn" @click="addBankCard">添加银行卡</button>
    </div>
  </div>
</template>
<script>
import noneList from '@/components/noneList.vue';
import { mapState,mapMutations } from 'Vuex';
import { Toast,MessageBox  } from 'mint-ui';
export default {
  name: "",
  data: () => ({
    cardList:[],
    noneList:false,
  }),
  components: {
    noneList,
  },
  mounted() {
    //do something after mounting vue instance
    let that = this;
    network.get(configUrl.USERCARDLIST_URL,'',function(res){
      console.log(res);
      let dataList = res.dataList;
      that.cardList = dataList;
      if(dataList.length<1){
        that.noneList = true;
      }else{
        that.noneList = false;
      }
    },function(err){
      console.log(err);
    });
  },
  methods: {
    ...mapMutations([
      'setIsbank',
      'setBankcard',
    ]),
    // 添加银行卡
    addBankCard() {
      this.$router.push({name:'addBankCard'});
    },
    pickBankcard(index) {    //选择银行卡，返回上一页
      let bankcard = this.cardList[index];
      eventBus.$emit('bankEvent', bankcard);
      this.setBankcard(bankcard);
      this.setIsbank();
      this.$router.go(-1);
    },
    // 删除银行卡
    delBank(cardId) {
      let self = this;
      MessageBox.confirm('确定删除该银行卡？').then(active=>{
        network.post(configUrl.DELETEUSERCARD_URL,{cardId:cardId},function(res) {
          console.log(res);
          Toast('银行卡删除成功');
          setTimeout(()=>{
            self.$router.go(0);   //刷新页面
          },500);
        },function(msg) {
          console.log(msg);
        })
      }).catch(error=>{
        console.log(error);
      })

    }
  }
}
</script>
<style lang="scss" scoped>

.bankcardList{
  padding: 20px;
  li{
    background: url('../../../../assets/images/VASA0@2x.png') no-repeat;
    background-size: 100% 100%;
    border-radius: 6px;
    height: 12rem;

    font-size: 16px;
    line-height: 2rem;
    margin-bottom: 20px;
    .cardA{
      @include flex;
      align-items: flex-start;
      flex-direction:column;
      justify-content: space-between;
    }
    div{
      width: 92%;
      color:white;
      padding:4%;
    }
    .bankNum{
      text-align: justify;
      display: block;
      font-size: 1.6rem;
      font-weight: normal;
      line-height: normal;
      margin-bottom: -26px;
      i{
        display:inline-block;width:100%;height:0; line-height:0;
        line-height: 0;
      }
    }
    .editImg{
      width: 20px;
      margin-right: 10px;
    }
    .deleteImg{
      width: 20px;
    }
  }
}
</style>
